//
//  TContactHeader.m
//  timelyRain
//
//  Created by Jiafei Wei on 16/9/22.
//  Copyright © 2016年 Jiafei Wei. All rights reserved.
//

#import "TContactHeader.h"
#import "TContactGroup.h"

@interface TContactHeader()
- (IBAction)clicked:(id)sender;
@property (weak, nonatomic) IBOutlet UIImageView *image;
@property (weak, nonatomic) IBOutlet UILabel *name;

@end
@implementation TContactHeader

+ (instancetype)headerViewWithTableView:(UITableView *)tableView//获取头文件
{
    static NSString *reuseId = @"header";
    TContactHeader *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:reuseId];
    if (header == nil){
        header = [[self alloc] initWithReuseIdentifier:reuseId];
    }
    return header;
}
//2 创建子控件 没有初始化frame
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        self = [[[NSBundle mainBundle] loadNibNamed:@"TContactHeader" owner:nil options:nil] lastObject];
    }
    return self;
}
- (IBAction)clicked:(id)sender {
    self.data.expend = !self.data.expend;//是否展开
    if (self.data.isExpend) {//展开
        self.image.transform = CGAffineTransformMakeRotation(M_PI_2);
    }else{//合并
        self.image.transform = CGAffineTransformMakeRotation(0);
    }

    if ([self.delegate respondsToSelector:@selector(headerViewDidClickedNameView:)]) {
        [self.delegate headerViewDidClickedNameView:self];
    }
}
-(void)setData:(TContactGroup *)data{
    _data =data;
    _name.text=_data.name;
    if (self.data.isExpend) {//展开
        self.image.transform = CGAffineTransformMakeRotation(M_PI_2);
    }else{//合并
        self.image.transform = CGAffineTransformMakeRotation(0);
    }
}
@end
